<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Validator;

class GoodsAttrRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'attr_type' => 'required',
            'attr_price' => 'required|regex:/^[\d]+\.?[\d]*$/',
        ];
    }
    
    public function messages() {
        return [
            'attr_type.required' => '属性名称不能为空',
            'attr_price.required' => '商品价格不能为空',
            'attr_price.regex' => '商品价格错误',
        ];
    }
    
    public function validateInput($data)
    {
        $message = Validator::make($data, $this->rules(), $this->messages());
        return $message->errors();
    }
}
